package org.nanotek.beans.mapping;

import java.lang.reflect.Field;

import org.nanotek.Base;
import org.nanotek.util.BeanReflectorBuilder;
import org.nanotek.util.Gettable;
import org.nanotek.util.Settable;
import org.nanotek.util.SizeAble;

/**
 * An attempt to use reflection to build a generic base class mapping using reflection.
 * ref. http://tutorials.jenkov.com/java-reflection/fields.html
 * @author josecanova
 *
 * @param <T>
 */
public class BaseMapping< T extends Base<?>> implements MappingPostConstructorStrategy<Base<?>>, Settable<Base<?>> , Gettable<Base<?>>, BeanReflectorBuilder<String[], Class<Base<?>>>, SizeAble {

	private Class<Base<?>> clazz;
	private String[] mapping;
	private Integer size;
	private Comparable<String> stringComparable;

	public BaseMapping(){
	}

	@Override
	public String[] buildMapping() {
		return createBeanInstance(mapping, clazz);
	}

	@Override
	public Class<Base<?>> getClazz() {
		return clazz;
	}

	@Override
	public void setClazz(Class<Base<?>> clazz) {
		this.clazz = clazz;
	}

	@Override
	public String[] createBeanInstance(String[] ref, Class<Base<?>> clazz) {

		Field[] fields= clazz.getFields();
		int i = size;
		for (Field field : fields){
			mapping[i] = field.getName();
		}

		for (i = fields.length ; i < mapping.length;i++)
			{
				mapping[i] = null;
			}

		return mapping;
	}

	@Override
	public void setSize(Integer size) {
	}

}
